<div class="row">
  <div class="col-xs-12">
    <div class="box box-primary">
      <div class="box-header">
        <h3 class="box-title">Edit Surat Jaminan</h3>
      </div><!-- /.box-header -->
      <?php echo form_open('surat_jaminan/update', array('role' => 'form', 'id' => 'form', 'enctype' => 'multipart/form-data'));
      if(!empty($list)){
      ?>
      <div class="box-body">				        
        <!-- text input -->
        <div class="row">	
      		<div class="col-sm-6">		        
            <!-- text input -->
            <div class="form-group">
              <label>No. Jaminan</label>
             	<input class="form-control input-sm" name="kd_surat_jaminan_disabled" type="text" value="<?= $list['kd_surat_jaminan'] ?>" placeholder="No. Surat Jaminan" disabled>
            	<input class="form-control input-sm" name="kd_surat_jaminan" type="hidden" value="<?= $list['kd_surat_jaminan'] ?>">
              <input class="form-control input-sm" name="kd_klaim" type="hidden" value="<?= $list['kd_klaim'] ?>">
            </div>
            <div class="form-group">
              <label>Nama</label>
             	<input class="form-control input-sm" name="nama" id="nama" type="text" value="<?= $list['nama'] ?>" placeholder="Nama Peserta" disabled>
            </div>
            <div class="form-group">
              <label>Alamat</label>
             	<input class="form-control input-sm" name="alamat" id="alamat" type="text" value="<?= $list['alamat'] ?>" placeholder="Alamat" disabled>
            </div>
            <div class="form-group">
              <label>Tempat, Tanggal Lahir</label>
             	<input class="form-control input-sm" name="ttl" id="ttl" type="text" value="<?= $list['tempat_lahir'].", ".id_date($list['tgl_lahir']) ?>" placeholder="Tempat, Tanggal Lahir" disabled>
            </div>
            <div class="form-group">
              <label>Tanggal Surat Jaminan</label>
              <input class="form-control input-sm" name="tanggal" id="tanggal" type="text" value="<?= id_date("$list[tgl_surat]", "datepicker", "") ?>" readonly style="background: #fff">
            </div>
            <div class="form-group">
              <label>PPK</label>
             	<select class="form-control input-sm" name="ppk">
             		<option value=""> - - Pilih PPK - - </option>
                <?php
                  foreach ($ppk as $value) {
                    if($value['kd_ppk'] == $list['kd_ppk']){
                      $s = "selected";
                    }else{
                      $s = "";
                    }
                    echo "<option value=".$value['kd_ppk']." $s>".$value['ppk']."</option>";
                  }
                ?>
             	</select>
            </div>
            <div class="form-group">
              <label>Jenis Kunjungan</label>
             	<select class="form-control input-sm" name="jenis_kunjungan" disabled>
             		<option value=""> - - Pilih Jenis Kunjungan - - </option>
                <?php
                  foreach ($jenis_kunjungan as $value) {
                    if($value['id_jenis_kunjungan'] == $list['id_jenis_kunjungan']){
                      $s = "selected";
                    }else{
                      $s = "";
                    }
                    echo "<option value=".$value['id_jenis_kunjungan']." $s>".$value['jenis_kunjungan']."</option>";
                  }
                ?>
             	</select>
            </div>
            <div class="form-group">
              <label>Kelas Perawatan</label>
             	<select class="form-control input-sm" name="kelas">
             		<option value="0"> - - Pilih Kelas Perawatan - - </option>
                <?php
                  foreach ($kelas_perawatan as $value) {
                    if($value['id_kelas_perawatan'] == $list['id_kelas_perawatan']){
                      $s = "selected";
                    }else{
                      $s = "";
                    }
                    echo "<option value=".$value['id_kelas_perawatan']." $s>".$value['kelas_perawatan']."</option>";
                  }
                ?>
             	</select>
            </div>
          </div>
          <div class="col-sm-6">
            <div class="form-group">
              <label>Rujukan</label>
              <select class="form-control input-sm" name="kd_rujukan">
                <option value="0"> - - Pilih PPK Rujukan - - </option>
                <?php
                  foreach ($ppk_rujukan as $value) {
                    if($value['kd_ppk'] == $list['kd_rujukan']){
                      $s = "selected";
                    }else{
                      $s = "";
                    }
                    echo "<option value=".$value['kd_ppk']." $s>".$value['ppk']."</option>";
                  }
                ?>
              </select>
            </div>
            <div class="form-group">
              <label>Keterangan</label>
              <textarea class="form-control input-sm" name="keterangan"><?= $list['keterangan'] ?></textarea>
            </div>
            <label>Diagnosa</label>
            <span class="pull-right">
              <a onClick="return add_data()" onclick="" class="btn btn-primary btn-xs btn-flat">
                <i class="fa fa-fw fa-plus"></i>
              </a>
            </span>
            <table class="table">
              <tbody id="tbl-diagnosa">  
                <?php
                  foreach ($diagnosa_jaminan as $val) {
                    ?>          
                      <tr>
                        <td>
                          <select class="form-control diagnosa" name="diagnosa[]">
                            <option value=""> - - Pilih Diagnosa - - </option>
                            <?php
                              foreach ($diagnosa as $value) {
                                if($value['kd_diagnosa'] == $val['kd_diagnosa']){
                                  $s = "selected";
                                }else{
                                  $s = "";
                                }
                                echo "<option value=".$value['kd_diagnosa']." $s>".$value['diagnosa']."</option>";
                              }
                            ?>
                          </select>
                        </td>
                        <td width="10%">
                          <a href="javascript:void(null)" class="btn btn-xs btn-danger btn-flat pull-right" title="Hapus" onclick="hapusData(this)">
                            <i class="fa fa-trash-o"></i>
                          </a>
                        </td>
                      </tr> 
                    <?php
                  }
                ?>                      
              </tbody>
              
            </table>
            <div class="form-group">
              <label>Diagnosa Lain</label>
              <input type="text" class="form-control input-sm" name="diagnosa_lain" value="<?= $list['diagnosa_lain'] ?>" id="diagnosa_lain">
            </div>
            <label>Lampiran</label>
            <p style="font-size: 12px;"> 
              <i>File yang diijinkan yang berekstensi .jpg/.png</i>
              <a onClick="return add_lampiran()" class="btn btn-primary btn-xs btn-flat pull-right">
                <i class="fa fa-fw fa-plus"></i>
              </a>
            </p>
            <table class="table">
              <tbody id="tbl-lampiran">            
                <tr>
                  <td>
                    <input type="file" name="lampiran[]">
                  </td>
                  <td width="10%"></td>
                </tr>                       
              </tbody>
            </table>
          </div>
        </div>
      </div>		                   
      <div class="box-footer">
        <button type="submit" class="btn btn-sm btn-primary btn-flat"><i class="fa fa-floppy-o"></i> Simpan</button>
      </div>
      <?php if (isset($_SERVER['HTTP_REFERER'])) {?>
        <input type="hidden" name="redirurl" value="<?php echo $_SERVER['HTTP_REFERER'];?>" />
      <?php }?>
			<?php
			}else{
			echo "Tidak ada data";	
			}
			echo form_close();
			?>
    </div><!-- /.box -->                            
  </div>
</div>

<script>
$("#form").validate({
  rules: {
    ppk: {
      required: true
    },
  }
});
</script>

<script type="text/javascript">
  $(document).ready(function(){
    $('#tanggal').datepicker({
      dateFormat: "dd/mm/yy",
      changeMonth: true,
      changeYear: true
    });
  });
</script>

<script type="text/javascript">
  $(document).ready(function() {
    $(".diagnosa").select2();
  });
</script>  

<script type="text/javascript">
  function hapusData(obj){  
    if (confirm('Apakah data akan dihapus ?')) {
      obj.parentNode.parentNode.parentNode.removeChild(obj.parentNode.parentNode);
    }
  }

  function add_data(){
    var tampil_tombol_aksi = '<a href="javascript:void(null)" class="btn btn-xs btn-danger btn-flat pull-right" title="Hapus" onclick="hapusData(this)"><i class="fa fa-trash-o"></i></a>';
    var tr = document.createElement('tr');
    var td_diagnosis = document.createElement('td');   
    var td_aksi = document.createElement('td');     
    var tbodi = document.getElementById("tbl-diagnosa");

    td_aksi.className = 'links';
    td_diagnosis.innerHTML = "<select class='form-control diagnosa' name='diagnosa[]'><option> - - Pilih Diagnosa - - </option><?php foreach ($diagnosa as $value) { echo "<option value='$value[kd_diagnosa]'>$value[diagnosa]</option>";}?></select>";
    td_aksi.innerHTML = tampil_tombol_aksi;
    tr.appendChild(td_diagnosis);
    tr.appendChild(td_aksi);
    tbodi.appendChild(tr);
    $(".diagnosa").select2();
  }
</script>  

<script type="text/javascript">
  function hapusLampiran(obj){  
    if (confirm('Apakah data akan dihapus ?')) {
      obj.parentNode.parentNode.parentNode.removeChild(obj.parentNode.parentNode);
    }
  }

  function add_lampiran(){
    var aksi_lampiran = '<a href="javascript:void(null)" class="btn btn-xs btn-danger btn-flat pull-right" title="Hapus" onclick="hapusLampiran(this)"><i class="fa fa-trash-o"></i></a>';
    var tr = document.createElement('tr');
    var td_lampiran = document.createElement('td');   
    var td_aksi = document.createElement('td');     
    var tbodi = document.getElementById("tbl-lampiran");

    td_aksi.className = 'links';
    td_lampiran.innerHTML = "<input type='file' name='lampiran[]'>";
    td_aksi.innerHTML = aksi_lampiran;
    tr.appendChild(td_lampiran);
    tr.appendChild(td_aksi);
    tbodi.appendChild(tr);
  }
</script>